﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Pseudogenerator.Views.WPF.Converters
{
    public class BoolToTextConverter
        : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value">Valor booleano enlazado</param>
        /// <param name="targetType"></param>
        /// <param name="parameter">Cadena con formato string1:string2. Si el valor booleano es true, se retorna el string1 de lo contrario string2. Si la caena especificada no tiene el formato string1:string2 se retorna una cadena vacia en caso de false.</param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var cadenas = parameter.ToString().Split(':');
            var val = (bool)value;
            var result = cadenas.Count() == 0 ? val.ToString() : (val ? cadenas[0] : cadenas.LastOrDefault(c => c != cadenas[0]) ?? "");
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
